<?php

namespace App\Http\Requests\dispatch;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait CarRequest
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'type_id' => 'required|integer',
            'agent_id' => 'required|numeric',
            'weight' => 'required|numeric',
            'volume' => 'required|numeric',
            'car_number' => 'required',
//            'driver_ids' => 'required',
        ], [
            'type_id.required' => '请选择类型',
            'agent_id.required' => '请选择代理商',
            'weight.required' => '请填写额载重量',
            'volume.required' => '请填写额载容积',
            'car_number.required' => '请填写车牌号',
//            'driver_ids.required' => '请选择司机',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
